var unload_fun_list = [];
var load_fun_list = [];
var list = [];
var focusList = [],
  blurList = [],
  beginAreaList = [],
  blurAreaList = [],
  selectList = [];
var fObjList = [];

var cssText = function (el, value) {
  if (_frameWork.isString(value)) {
    if (el.style.cssText.length > 1) {
      el.style.cssText += value;
    } else {
      var style = value.split(';');
      for (var m = 0; m < style.length; ++m) {
        var item = style[m].split(':');
        el.style[item[0]] = item[1];
      }
    }
    return true;
  }
};

var _frameWork = {
  /*核心参数*/
  objects: {},
  focObj: null,
  areaLastFocus: {},
  prevFocObj: null,
  prevArea: null,
  focArea: null,
  direction: null,
  defaultUpCode: [1, 38],
  defaultDownCode: [2, 40],
  defaultLeftCode: [3, 37],
  defaultRightCode: [4, 39],
  defaultDoCode: [13],
  defaultBackCode: [8, 27, 45, 340],
  defaultNumberCode: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57],

  // 清空list
  clearList: function () {
    list = [];
    focusList = [];
    blurList = [];
    beginAreaList = [];
    blurAreaList = [];
    selectList = [];
    fObjList = [];
    this.defaultEvenFn();
  },

  defaultEvenFn: function () {
    this.addEvenToList(this.defaultUpCode, function () {
      _frameWork.up();
    });
    this.addEvenToList(this.defaultDownCode, function () {
      _frameWork.down();
    });
    this.addEvenToList(this.defaultLeftCode, function () {
      _frameWork.left();
    });
    this.addEvenToList(this.defaultRightCode, function () {
      _frameWork.right();
    });
    this.addEvenToList(this.defaultDoCode, function () {
      _frameWork.doSelect();
    });
    this.addEvenToList(this.defaultBackCode, function () {
      _frameWork.memoryO.goBack();
    });
  },
  // 禁用上下左右确认返回键的响应, 可恢复原有状态
  forbiddenAllEvenCode: function () {
    this.addEvenToList(this.defaultUpCode, function () {
    });
    this.addEvenToList(this.defaultDownCode, function () {
    });
    this.addEvenToList(this.defaultLeftCode, function () {
    });
    this.addEvenToList(this.defaultRightCode, function () {
    });
    this.addEvenToList(this.defaultDoCode, function () {
    });
    this.addEvenToList(this.defaultBackCode, function () {
    });
  },

  /*默认事件处理*/
  defaultBackFn: function () {
    this.addEvenToList(this.defaultBackCode, function () {
      _frameWork.memoryO.goBack();
    });
  },
  /*默认事件处理*/
  defaultDoFn: function () {
    this.addEvenToList(this.defaultDoCode, function () {
      _frameWork.doSelect();
    });
  },
  /**
   *
   * @param _group Array
   * @param _fn
   */
  addFocus: function (_group, _fn) {
    this.addEvenToList(_group, _fn, focusList);
  },
  /**
   *
   * @param _group Array
   * @param _fn
   */
  addBeginArea: function (_group, _fn) {
    this.addEvenToList(_group, _fn, beginAreaList);
  },
  /**
   *
   * @param _group Array
   * @param _fn
   */
  addBlur: function (_group, _fn) {
    this.addEvenToList(_group, _fn, blurList);
  },
  /**
   *
   * @param _group Array
   * @param _fn
   */
  addBlurArea: function (_group, _fn) {
    this.addEvenToList(_group, _fn, blurAreaList);
  },
  /**
   *
   * @param _group Array
   * @param _fn
   */
  addSelect: function (_group, _fn) {
    this.addEvenToList(_group, _fn, selectList);
  },
  hasClass: function (obj, c_name) {
    var oldClass = obj.className;
    var reg = new RegExp(' ' + c_name + ' ', 'g');
    return reg.test(' ' + oldClass + ' ');
  },

  addClass: function (obj, c_name) {
    if (this.hasClass(obj, c_name)) {
      return;
    }
    var oldClass = obj.className;
    var newClass = (oldClass + ' ' + c_name).replace(/(^\s*)|(\s*$)/g, '');
    obj.className = newClass;
  },

  removeClass: function (obj, c_name) {
    var oldClass = obj.className;
    var reg = new RegExp(c_name, 'g');
    var newClass = oldClass.replace(reg, '').replace(/(^\s*)|(\s*$)/g, '');
    obj.className = newClass;
  },

  initFocus: function (objid, holdOut) {
    if (objid == '' || objid == null) {
      console.log('ERROR:hs.initFocus(' + objid + '),objid is not defined!');
      return;
    }
    this.doFocus(objid, holdOut);
  },

  doFocus: function (jdomid, holdOut) {
    var holdOutFlag = holdOut || false;
    if (jdomid == null) return;
    var newObj = this.objects[jdomid];
    if (!newObj) {
      console.log('ERROR : ' + jdomid + '未注册fObject对象!');
      return;
    }

    var area = newObj.group;

    this.prevFocObj = this.focObj;

    if (this.focObj != null) {
      if (!holdOutFlag) {
        this.execBlur(
          this.focObj.group,
          this.focObj.objid,
          this.focObj.objindex
        );
      }
      if (this.focObj.group != area) {
        this.prevArea = this.focObj.group;
        this.execBlurArea(
          this.focObj.group,
          this.focObj.objid,
          this.focObj.objindex
        );
      }
    }

    var isAreaLastFocus =
      typeof this.areaLastFocus[area] != 'undefined' &&
      this.areaLastFocus[area] != null &&
      this.prevFocObj != null &&
      area != this.prevFocObj.group;

    if (this.focObj == null || this.focObj.group != area) {
      var obj = isAreaLastFocus ? this.areaLastFocus[area] : newObj;
      this.execBeginArea(obj.group, obj.objid, obj.objindex);
    }

    this.focArea = area;

    //this.focObj 新焦点
    if (isAreaLastFocus) {
      this.focObj = this.areaLastFocus[area];
      this.execFocus(
        this.areaLastFocus[area].group,
        this.areaLastFocus[area].objid,
        this.areaLastFocus[area].objindex
      );
    } else {
      //当区域对象无的的时候
      this.focObj = newObj;
      this.areaLastFocus[newObj.group] = this.focObj;
      this.execFocus(
        this.focObj.group,
        this.focObj.objid,
        this.focObj.objindex
      );
    }
  },
  execFocus: function (group, objid, objindex) {
    this.initExec(group, objid, objindex, focusList);
  },
  execBlur: function (group, objid, objindex) {
    this.initExec(group, objid, objindex, blurList);
  },
  execBeginArea: function (group, objid, objindex) {
    this.initExec(group, objid, objindex, beginAreaList);
  },
  execBlurArea: function (group, objid, objindex) {
    this.initExec(group, objid, objindex, blurAreaList);
  },
  execSelect: function (group, objid, objindex) {
    this.initExec(group, objid, objindex, selectList);
  },
  initExec: function (group, objid, objindex, _list) {
    for (var k = 0; k < _list.length; k++) {
      if (typeof _list[k].key == 'number') {
        if (_list[k].key == group) {
          _list[k].action(group, objid, objindex);
        }
      } else {
        for (var m = 0; m < _list[k].key.length; m++) {
          if (_list[k].key[m] == group) {
            _list[k].action(group, objid, objindex);
            return;
          }
        }
      }
    }
  },
  up: function () {
    if (this.focObj == null || this.focObj.up == null) {
      console.log('ERROR : doUp error!');
      return;
    }
    this.direction = 1;
    var up = this.focObj.up;

    if (typeof up == 'function') {
      this.focObj.doUp();
      return;
    }

    this.doFocus(up);
  },
  down: function () {
    if (this.focObj == null || this.focObj.down == null) {
      console.log('ERROR : doDown error!');
      return;
    }
    this.direction = 2;
    var down = this.focObj.down;

    if (typeof down == 'function') {
      this.focObj.doDown();
      return;
    }

    this.doFocus(down);
  },
  left: function () {
    if (this.focObj == null || this.focObj.left == null) {
      console.log('ERROR : doLeft error!');
      return;
    }
    this.direction = 3;
    var left = this.focObj.left;

    if (typeof left == 'function') {
      this.focObj.doLeft();
      return;
    }

    this.doFocus(left);
  },
  right: function () {
    if (this.focObj == null || this.focObj.right == null) {
      console.log('ERROR : doRight error!');
      return;
    }
    this.direction = 4;
    var right = this.focObj.right;

    if (typeof right == 'function') {
      this.focObj.doRight();
      return;
    }
    this.doFocus(right);
  },
  doSelect: function () {
    if (!this.focObj) {
      console.log('ERROR : doSelect error!');
      return;
    }
    // this.focObj.doSelect();
    this.execSelect(
      this.focObj.group,
      this.focObj.objid,
      this.focObj.objindex
    );
  },
  add: function (fObject) {
    var oid = fObject.objid;
    this.objects[oid] = fObject;
  },
  isDomExist: function (objid) {
    if ($(objid)) {
      return false;
    } else {
      return true;
    }
  },
  getId: function (dom) {
    if (dom) {
      return dom.getAttribute('id');
    } else {
      console.log('dom 为空');
      return;
    }
  },
  fObjCommit: function () {
    for (var i = 0; i < fObjList.length; i++) {
      _frameWork.add(fObjList[i]);
    }
    fObjList = [];
  },
  /**
   *
   * @param ele
   * @param attr
   * @returns {*}
   */
  getStyle: function (ele, attr) {
    if (window.getComputedStyle) {
      return window.getComputedStyle(ele, null)[attr];
    }
    return ele.currentStyle[attr];
  },

  getBaseUrl: function (projectName) {
    if (!projectName) {
      alert('缺少必要参数projectName');
    }
    return (
      location.href.substring(0, location.href.indexOf(projectName)) +
      projectName +
      '/'
    );
  },

  /*
  接口说明：
  功能：页面跳转到一个指定的地址
  参数：_url，要跳转到的地址
  */
  go: function (_url) {
    window.location.href = _url;
  },

  /*
  接口说明：
  功能：指定页面onload的处理方法
  参数：fn，需要处理的方法
        isAdd，是否为添加方式
               如果是添加方式，保留前次添加的所有方法
               如果非添加方式，会清除前次添加的所有方法
  */
  load: function (fn, isAdd) {
    if (typeof fn === 'function') {
      if (typeof isAdd === 'boolean' && isAdd == false) {
        load_fun_list = [];
      }

      load_fun_list.push(fn);
      window.onload = function () {
        for (var i = 0; i < load_fun_list.length; i++) {
          load_fun_list[i]();
        }
      };
    }
  },

  /*
  接口说明：
  功能：指定页面onunload的处理方法
  参数：fn，需要处理的方法
        isAdd，是否以添加方式指定
               如果是添加方式，保留前次添加的所有方法
               如果非添加方式，会清除前次添加的所有方法
  */
  unload: function (fn, isAdd) {
    if (typeof fn === 'function') {
      if (typeof isAdd === 'boolean' && isAdd == false) {
        unload_fun_list = [];
      }

      unload_fun_list.push(fn);
      window.onunload = function () {
        for (var i = 0; i < unload_fun_list.length; i++) {
          unload_fun_list[i]();
        }
      };
    }
  },
  /*事件监听增加处理*/
  defaultFun: function (key_code) {
    var ret = 1;
    for (var k = 0; k < list.length; k++) {
      for (var m = 0; m < list[k].key.length; m++) {
        if (list[k].key[m] == key_code) {
          if (this.arrayIsContains(this.defaultNumberCode, key_code))
            key_code -= 48;
          list[k].action(key_code);
          ret = 0;
          break;
        }
      }
    }
    return ret;
  },
  /*
  接口说明：
  功能：在默认处理监听事件的方法中，增加对一组按键值的处理
  参数：_key，按键值列表，为整形的数组
        _fun，对应按键值的处理方法
  */
  addEvenToList: function (_key, _fun, _list) {
    var ls = _list || list;
    var isExist = false;
    var obj = {
      key: _key,
      action: _fun
    };
    for (var k = 0; k < _key.length; k++) {
      isExist = this.removeFromList(_key[k], obj, ls);
    }
    if (!isExist) {
      ls.push(obj);
    }
  },

  /*
     接口说明：
     功能：在默认处理监听事件的方法中，删除对单个按键值的处理
     参数：_key，按键值，为单个整形值
     */
  removeFromList: function (_key, obj, _list) {
    var ls = _list || list;
    var isExist = false;
    for (var k = 0; k < ls.length; k++) {
      for (var m = 0; m < ls[k].key.length; m++) {
        if (ls[k].key[m] == _key) {
          ls.splice(k, 1, obj);
          isExist = true;
          break;
        }
      }
    }
    return isExist;
  },

  /**
   * ajax
   */
  AjaxObject: function () {
    var geturl1 = 'http://21.254.5.190/UnityService/WcfService.svc/';
    // 省网图文
    var geturl2 = 'http://21.254.5.190/UTLService/UIL/Publish/Handler.ashx';
    // 杭网图文
    var geturl3 = 'http://vas-add.wasu.cn/UTLService/UIL/Publish/Handler.ashx';

    var ajaxUrl = '';
    var timeout = 500;
    var _t = null;
    var xmlhttp = null;
    var loadStuts = false;
    this.async = true;
    var that = this;

    var init = function (_url, _type, _timeout) {
      if (typeof _url == 'string') {
        ajaxUrl = _url;
      }

      if (typeof _type == 'number') {
        switch (_type) {
          case 1:
            ajaxUrl = geturl1 + ajaxUrl;
            break;
          case 2:
            ajaxUrl = geturl2 + ajaxUrl;
            break;
          case 3:
            ajaxUrl = geturl3 + ajaxUrl;
            break;
        }
      }

      if (typeof _timeout == 'number') {
        timeout = _timeout;
      }
    };

    var destroy = function () {
      if (xmlhttp != null) {
        xmlhttp.abort();
        xmlhttp = null;
      }
      loadStuts = false;
    };

    /*

      接口说明：
      功能：发起ajax请求
      参数：_method，请求方法，为“POST”或“GET”
            _url，请求地址
            _data，只有方法为“POST”时有效，post数据，为数组类型，数组元素遵循“变量名=变量值”格式
            _fun，正确返回的回调地址
            _type, 前缀地址
            _err，错误返回执行函数
            _timeout，超时时间
  */

    var ajax_method = function (
      _method,
      _url,
      _data,
      _fun,
      _type,
      _err,
      _timeout
    ) {
      if (
        typeof _method != 'string' ||
        ('POST' != _method && 'GET' != _method)
      ) {
        _err('_method ERROR!');
      }
      init(_url, _type, _timeout);
      if (ajaxUrl) {
        destroy();
        xmlhttp = new XMLHttpRequest();

        // 将 object 类型的参数转换为 key=value&key=value
        if (typeof _data === 'object') {
          var tempArr = [];
          for (var key in _data) {
            var value = _method == 'GET' ?
              key + '=' + encodeURIComponent(_data[key]) :
              key + '=' + _data[key];
            tempArr.push(value);
          }
          _data = tempArr.join('&');
        }
        if (xmlhttp != null) {
          xmlhttp.open(_method, ajaxUrl, that.async);
          if (that.async) {
            setMyTimeOut(_err);
            xmlhttp.onreadystatechange = function () {
              if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                if (loadStuts) return;
                clearTimeOut();
                var str = xmlhttp.responseText;
                _fun(str);
              }
            };
          }

          if ('POST' == _method && _data != null) {
            xmlhttp.setRequestHeader(
              'Content-type',
              'application/x-www-form-urlencoded'
            );
            xmlhttp.send(_data);
          } else {
            xmlhttp.send();
          }

          if (!that.async) {
            var str = xmlhttp.responseText;
            _fun(str);
          }
        } else {
          _err('xmlhttp is null!');
        }
      }
    };

    this.get = function (_url, _fun, _type, _err, _timeout) {
      ajax_method('GET', _url, null, _fun, _type, _err, _timeout);
    };

    this.post = function (_url, _data, _fun, _type, _err, _timeout) {
      ajax_method('POST', _url, _data, _fun, _type, _err, _timeout);
    };

    var setMyTimeOut = function (_err) {
      clearTimeOut();
      _t = setTimeout(function () {
        dealErr(_err);
      }, timeout);
    };

    var clearTimeOut = function (_err) {
      if (_t != null) {
        clearTimeout(_t);
      }
    };

    var dealErr = function (_err) {
      if (loadStuts == false) {
        loadStuts = true;
        xmlhttp.abort();
        _err('请求超时!');
      }
    };
  },
  scroll: {
    scrollWidth: 0,
    _text_width: 0,
    _text_left: 0,//变化中的text left
    _inc: 1.5,//滚动方向
    _scrollObj: null,


    scrollText: function (scrollObj, _scrollWidth) {
      this._text_width = scrollObj.offsetWidth
      this._text_left = 0;
      this._scrollObj = scrollObj;
      this.scrollWidth = _scrollWidth;
      if (this._text_width <= this.scrollWidth) {
        this.stopScroll(this._scrollObj);
      } else if (scrollObj.scrollTimeout == null) {
        this._text_width += 140
        this._scrollObj.style.left = 0 + "px";
        scrollObj.scrollTimeout = setInterval(function () {
          _frameWork.scroll.moveText();
        }, 50);
      }
    },

    //每间隔1s移动text
    moveText: function () {
      if (this._text_left < this.scrollWidth - this._text_width) {
        this._inc = -1.5;
      } else if (this._text_left <= 6 && this._text_left > 2) {
        this._inc = 1.5;
      }
      this._text_left -= this._inc;
      this._scrollObj.style.left = this._text_left + "px";
    },
    stopScroll: function (scrollObj) {
      if (scrollObj.scrollTimeout) {
        clearInterval(scrollObj.scrollTimeout);
        scrollObj.scrollTimeout = null;
        scrollObj.style.left = "0px";
      }
    }
  },
  /**
   * xml
   */
  xml: {
    loadXML: function (xmlFile) {
      var xmlDoc;
      if (!!window.ActiveXObject || 'ActiveXObject' in window) {
        var xmlDomVersions = [
          'MSXML.2.DOMDocument.6.0',
          'MSXML.2.DOMDocument.3.0',
          'Microsoft.XMLDOM',
        ];
        for (var i = 0; i < xmlDomVersions.length; i++) {
          try {
            xmlDoc = new ActiveXObject(xmlDomVersions[i]);
            xmlDoc.async = false;
            xmlDoc.loadXML(xmlFile);
            break;
          } catch (e) {
          }
        }
      } else if (navigator.userAgent.indexOf('Firefox') > 0) {
        //火狐浏览器
        xmlDoc = document.implementation.createDocument('', '', null);
        xmlDoc.load(xmlFile);
      } else {
        //谷歌浏览器
        xmlDoc = new DOMParser().parseFromString(xmlFile, 'text/xml');
      }
      return xmlDoc;
    },
  },
  /**
   * media
   */
  mw: {
    getSiteInfo: function (siteID, siteIndex, siteItem) {
      var base_url = 'http://125.210.227.229/catalog';
      var content = {
        data: [],
        pages: ''
      };
      var data = '<?xml version="1.0" encoding="UTF-8"?>';
      data +=
        '<message module="CATALOG_SERVICE" version="1.0">' +
        '<header component-type="REQUEST" action="REQUEST" component-id="catalog" sequence="100000001" command="RELATIVE_CONTENT_QUERY" version="2.0"/>' +
        '<body>' +
        '               <folders>' +
        '                   <folder>' +
        '<site-code>hzvsite</site-code>' +
        '<code>' +
        siteID +
        '</code>' +
        '<page-index>' +
        siteIndex +
        '</page-index>' +
        '<page-items>' +
        siteItem +
        '</page-items>' +
        '</folder>' +
        '</folders>' +
        '           </body>' +
        '</message>';

      _frameWork.ajax.post(
        'http://21.254.5.190/UTLService/UIL/Cross/Handler.ashx',
        'url=' +
        base_url +
        '&data=' +
        encodeURIComponent(
          data.replace(/</gi, '&lt;').replace(/>/gi, '&gt;')
        ) +
        '&method=soap',
        function (response) {
          // console.log(response);
          if (response.indexOf('未查询到任何内容信息') != -1) {
            console.log('未查询到任何内容信息!');
          } else {
            var xmlDoc = _frameWork.xml.loadXML(response); //loadXML方法载入xml字符串
            var elements = xmlDoc.getElementsByTagName('content');
            var pages = xmlDoc
              .getElementsByTagName('contents')[0]
              .getAttribute('total-pages');
            for (var i = 0; i < elements.length; i++) {
              var name = elements[i].getElementsByTagName('name')[0].firstChild
                .nodeValue;
              var creatTime = elements[i].getElementsByTagName('creat-time')[0]
                .firstChild.nodeValue;
              var code = elements[i].getElementsByTagName('code')[0].firstChild
                .nodeValue;
              var imgUrl = elements[i].getElementsByTagName('url').length > 1 ?
                elements[i].getElementsByTagName('url')[1].firstChild
                  .nodeValue :
                null;
              content.data.push({
                codeID: code,
                name: name,
                creatTime: creatTime,
                imgUrl: imgUrl,
                playUrl: '',
              });
              content.pages = pages;
            }
          }
        },
        null,
        function (msg) {
          console.log(msg);
        },
        3500
      );
      /*for (var i = 0; i < content.data.length; i++) {
          content.data[i].playUrl = this.getSite2Url(siteID, content.data[i].codeID,1);
      }*/
      return content;
    },
    /*type 1省网*/
    getSite2Url: function (siteID, contentID, types) {
      var types = types || 1;
      var rp1_s = '&owchid=hdds_ip&isHD=0&isIpqam=0'; //省网后缀
      var rp1 = 'rtsp://21.254.5.198:554'; //省网匹配

      var base_url = 'http://125.210.227.229/catalog';
      var data =
        '<?xml version="1.0" encoding="UTF-8" ?>' +
        '<message module="CATALOG_SERVICE" version="1.0">' +
        '<header component-type="REQUEST" action="REQUEST" component-id="catalog" sequence="100000001" command="CONTENT_URL_QUERY" version="2.0"/>' +
        '<body>' +
        '<contents>' +
        '<content>' +
        '<site-code>hzvsite</site-code>' +
        '<folder-code>' +
        siteID +
        '</folder-code>' +
        '<code>' +
        contentID +
        '</code>' +
        '<items-index>1</items-index>' +
        '<format>50</format>' +
        /*  '<begin-time></begin-time>'+
            '<end-time></end-time>'+
            '<file-index></file-index>'+ */
        '</content>' +
        '</contents>' +
        '</body>' +
        '</message>';
      var str = '';
      _frameWork.ajax.post(
        'http://21.254.5.190/UTLService/UIL/Cross/Handler.ashx',
        'url=' +
        base_url +
        '&data=' +
        encodeURIComponent(
          data.replace(/</gi, '&lt;').replace(/>/gi, '&gt;')
        ) +
        '&method=soap',
        function (response) {
          // console.log(response);
          if (types == 1) {
            var xmlDoc = _frameWork.xml.loadXML(response);
            var elements = xmlDoc.getElementsByTagName('play-urls');
            for (var i = 0; i < elements.length; i++) {
              var urls = elements[i].getElementsByTagName('play-url');
              for (var j = 0; j < urls.length; j++) {
                var url = urls[j].firstChild.nodeValue;
                if (url.indexOf(rp1) != -1 && url.indexOf('&isHD=0') != -1) {
                  str = url.substring(0, url.indexOf('&')) + rp1_s;
                  break;
                }
              }
            }
          } else {
            /*杭网*/
            /*var tmp = response.substring(response.indexOf(rp2));
              tmp = tmp.substring(0,tmp.indexOf('&token'));
              contentPlayUrl.push(tmp);*/
          }
        },
        null,
        function (msg) {
          console.log(msg);
        },
        3500
      );
      return str;
    },
    /*types == 1省*/
    getConidToUrl: function (contentID, types) {
      var rp2 = 'rtsp://125.210.227.234:5541/hdds_ip';
      // var rp1_s = "&owchid=vod01_channel&isHD=0&isIpqam=0";//省网后缀
      // var rp1 = "rtsp://21.254.5.158:554";//省网匹配
      var rp1_s = '&owchid=hdds_ip&isHD=0&isIpqam=0'; //省网后缀
      var rp1 = 'rtsp://21.254.5.198:554'; //省网匹配
      var url = 'http://125.210.227.229/catalog';
      var values =
        '<?xml version="1.0" encoding="UTF-8"?>' +
        '<message module="CATALOG_SERVICE" version="1.0">' +
        '<header component-type="REQUEST" action="REQUEST" component-id="catalog" sequence="100000001" command="CONTENT_URL_QUERY" version="2.0"/>' +
        '<body>' +
        '<contents>' +
        '<content>' +
        '<code>' +
        contentID +
        '</code>' +
        '<items-index>1</items-index>' +
        '<site-code>hzvsite</site-code>' +
        '<format>50</format>' +
        '</content>' +
        '</contents>' +
        '</body>' +
        '</message>';

      var res = '';
      var str = '';
      _frameWork.ajax.post(
        'http://125.210.113.145/WSL/Core/CrossDomain.ashx',
        'url=' +
        encodeURIComponent(url) +
        '&data=' +
        encodeURIComponent(
          values.replace(/</gi, '&lt;').replace(/>/gi, '&gt;')
        ) +
        '&method=post&type=soap',
        function (obj) {
          // console.log('getConidToUrl');
          res = obj;
        },
        0,
        3000
      );

      // var res = request.getAllResponseHeaders() + request.responseText;
      if (types == 1) {
        var xmlDoc = _frameWork.xml.loadXML(res);
        var elements = xmlDoc.getElementsByTagName('play-urls');
        for (var i = 0; i < elements.length; i++) {
          var urls = elements[i].getElementsByTagName('play-url');
          for (var j = 0; j < urls.length; j++) {
            var url = urls[j].firstChild.nodeValue;
            if (url.indexOf(rp1) != -1 && url.indexOf('&isHD=0') != -1) {
              str = url.substring(0, url.indexOf('&')) + rp1_s;
              break;
            }
          }
        }
        return str;
      } else {
        var tmp = res.substring(res.indexOf(rp2));
        return tmp.substring(0, tmp.indexOf('&token'));
      }
    },
  },
  cookie: {
    get: function (name) {
      var arr, reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
      if ((arr = document.cookie.match(reg))) {
        if (arr[2].indexOf('"') === 0) {
          arr[2] = arr[2]
            .slice(1, -1)
            .replace(/\\"/g, '"')
            .replace(/\\\\/g, '\\');
        }
        try {
          arr[2].replace(/\+/g, ' ');
          return decodeURIComponent(arr[2]);
        } catch (e) {
          console.log(e.message);
        }
      } else {
        return null;
      }
    },
    /**
     *
     * @param name
     * @param value
     * @param days
     */
    set: function (name, value, days) {
      var exp = new Date();
      exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
      if (days) {
        window.document.cookie =
          name +
          '=' +
          encodeURIComponent(value) +
          ';expires=' +
          exp.toGMTString() +
          ';path=/';
      } else {
        window.document.cookie =
          name + '=' + encodeURIComponent(value) + ';path=/';
      }
    },
    delOne: function (name) {
      var exp = new Date();
      exp.setTime(exp.getTime() - 1);
      var cval = this.get(name);
      if (cval != null) {
        document.cookie =
          name + '=' + cval + ';expires=' + exp.toGMTString() + ';path=/';
      }
    },
    delAll: function () {
      var strCookie = document.cookie;
      var arrCookie = strCookie.split('; '); // 将多cookie切割为多个名/值对
      for (var i = 0; i < arrCookie.length; i++) {
        // 遍历cookie数组，处理每个cookie对
        if (arrCookie[i].indexOf('=') != -1) {
          var arr = arrCookie[i].split('=');
          if (arr.length > 0) this.delOne(arr[0]);
        } else if (arrCookie[i].indexOf(';') != -1) {
          var nn = arrCookie[i].indexOf(';');
          var arr = arrCookie[i].substring(0, nn);
          if (arr.length > 0) this.delOne(arr);
        }
      }
    },
  },
  /**
   * global
   * @private
   */
  global: {
    get: function (name) {
      var GlobalValue = '';
      try {
        GlobalValue = iPanel.getGlobalVar(name);
      } catch (e) {
        console.log(e.message);
        return null;
      }
      return GlobalValue;
    },
    set: function (name, value) {
      try {
        iPanel.setGlobalVar(name, value);
      } catch (e) {
        console.log(e.message);
      }
    },
    del: function (key) {
      try {
        iPanel.delGlobalVar(key);
      } catch (e) {
        console.log(e.message);
      }
    },
  },
  /**
   * locationUrl
   */
  locationUrl: {
    /**
     * @param _u
     * @returns {string|*}
     */
    getQueryString: function (name) {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return decodeURIComponent(r[2]);
      return '';
    },
    // 判定浏览器厂商信息
    getNavigatorUA: function () {
      var _ua = navigator.userAgent.toLowerCase();
      if (/ipanel/.test(_ua)) {
        return 'iPanel';
      } else if (/windows /.test(_ua)) {
        return 'PC';
      }
      return _ua;
    },
    /**
     *
     * @param _u
     * @param _k
     * @param _v
     * @returns {string|*}
     */
    setQueryString: function (_u, _k, _v) {
      _u.indexOf('?') != -1 ? (_u += '&') : (_u += '?');
      _u += _k + '=' + encodeURIComponent(_v);
      return _u;
    },
  },
  /**
   * 返回处理
   */
  memoryO: {
    goBack: function () {
      window.history.go(-1);
    },
  },
  /*
    接口说明：
    功能：从秒转换到字符串
    参数：_second，大于0，小于一天（24小时）
    返回值：输出字符串格式为hh:mm:ss
            小于0，或大于一天，则返回"00:00:00"
    */
  formatTime: function (_second) {
    if (typeof _second != 'number' || _second < 0 || _second >= 86400) {
      return '00:00:00';
    }

    var o = {
      'h+': parseInt(_second / 3600),
      'm+': parseInt(_second / 60 % 60),
      's+': _second % 60,
    };

    var _fmt = 'hh:mm:ss';
    for (var k in o) {
      if (new RegExp('(' + k + ')').test(_fmt)) {
        _fmt = _fmt.replace(
          RegExp.$1,
          RegExp.$1.length == 1 ?
            o[k] :
            ('00' + o[k]).substr(('' + o[k]).length)
        );
      }
    }
    return _fmt;
  },

  /*
  接口说明：
  功能：从hh:mm:ss格式字符串转换到数字秒
  参数：hh:mm:ss格式字符串
  返回值：输出数字秒
  */
  formatToTime: function (_stime) {
    if (typeof _stime != 'string' || _stime.length != 8) {
      return 0;
    }

    var a = _stime.split(':');
    if (a.length != 3) {
      return 0;
    }
    var sum =
      parseFloat(a[0]) * 3600 + parseFloat(a[1]) * 60 + parseFloat(a[2]);
    try {
      return sum;
    } catch (e) {
      return 0;
    }
  },
  listenLive: function () {
    let _this = this;
    this.nowTime = '';
    this.beforeTime = '';
    this.startTime = '';
    this.endTime = '';
    this.afterTime = '';
    this.playUrl = '';
    this.beforeImg = '';
    this.errorFlag = 0;
    this.intTime = null;
    this.delayTime = 30;
    this.isStart = false;
    this.isAfter = false;
    this.isBefore = false;
    this.bridge = {};
    this.store = {};
    this.vedioInfo = {};
    this.execFlag = true
    this.status = 0


    this.formateTime = function (time) {
      return time.replace(' ', 'T').replace(/[-:]/g, '') + 'Z';
    };
    this.setMw = function () {
      /*当前时间减3分钟*/
      let sTimeL = _this.nowTime.split(' ')[0];
      let sTimeR = _frameWork.formatToTime(_this.nowTime.split(' ')[1]);
      sTimeR = parseInt(sTimeR) - _this.delayTime;
      let sTime = _this.formateTime(
        sTimeL + ' ' + _frameWork.formatTime(sTimeR)
      );
      let eTime = _this.formateTime(_this.endTime);

      let url = _frameWork.locationUrl.setQueryString(_this.playUrl, "start-time", sTime)
      url = _frameWork.locationUrl.setQueryString(url, "stop-time", eTime)
      console.log(url)
      _this.bridge.movies = [
        url
      ];
      _this.bridge.countFlag = 0;
      _this.bridge.initPlay();
    };
    this.setOldMw = function () {
      /* 开始时间 */
      let sTimeL = _this.startTime.split(' ')[0];
      // var sTimeR = parseInt(hs.formatToTime(startTime.split(" ")[1])) - 180 + delayTime;
      let sTimeR = parseInt(
        _frameWork.formatToTime(_this.startTime.split(' ')[1])
      );
      let sTime = _this.formateTime(
        sTimeL + ' ' + _frameWork.formatTime(sTimeR)
      );

      /* 结束时间 */
      let eTimeL = _this.endTime.split(' ')[0];
      // var eTimeR = parseInt(hs.formatToTime(endTime.split(" ")[1])) - 180;
      let eTimeR = parseInt(
        _frameWork.formatToTime(_this.endTime.split(' ')[1])
      );
      let eTime = _this.formateTime(
        eTimeL + ' ' + _frameWork.formatTime(eTimeR)
      );
      let url = _frameWork.locationUrl.setQueryString(_this.playUrl, "start-time", sTime)
      url = _frameWork.locationUrl.setQueryString(url, "stop-time", eTime)
      _this.bridge.movies = [
        url
      ];
      _this.bridge.countFlag = 0;
      _this.bridge.initPlay();
    };
    this.getStatus = function () {
      _frameWork.ajax.get(
        'http://125.210.113.145/WSL/Core/DateFormat.ashx?style=40',
        function (obj) {
          obj = JSON.parse(obj);
          // console.log(obj);
          if (obj.Success == true) {
            _this.nowTime = obj.Data.DateFormat;
          }
        }, 0, function (msg) {
        }, 3000);
      //当前时间
      let nowTimeTemp = _this.nowTime;
      nowTimeTemp = parseInt(
        this.formateTime(nowTimeTemp).replace(/[TZ]/g, '')
      );
      //开始时间
      let startTimeTemp = _this.startTime;
      startTimeTemp = parseInt(
        this.formateTime(startTimeTemp).replace(/[TZ]/g, '')
      );
      //结束时间
      let endTimeTemp = _this.endTime;
      endTimeTemp = parseInt(
        this.formateTime(endTimeTemp).replace(/[TZ]/g, '')
      );

      let tempBeforeTime = _this.beforeTime;
      tempBeforeTime = parseInt(
        this.formateTime(tempBeforeTime).replace(/[TZ]/g, '')
      );

      let tempAfterTime = _this.afterTime;
      tempAfterTime = parseInt(
        this.formateTime(tempAfterTime).replace(/[TZ]/g, '')
      );

      /*预热中 ,当前时间在开始时间和预热时间之间*/
      if (
        (nowTimeTemp < startTimeTemp && nowTimeTemp >= tempBeforeTime) ||
        _this.errorFlag === -1
      ) {
        console.log('预热中');
        if (!_this.execFlag) {
          this.status = 0
          return this.status
        }
        // $("nav2_0_bg").style.display = "block";
        // hs.mw.closeMedia();
        this.store.commit('setLive', {
          defaultImg: _this.beforeImg,
          status: '预热中',
        });
        _this.isStart = false;
        _this.isAfter = false;
        _this.isBefore = false;

        /*直播中 ,当前时间在开始时间和结束时间之间*/
      } else if (nowTimeTemp >= startTimeTemp && nowTimeTemp <= endTimeTemp) {
        console.log('直播中');
        if (!_this.execFlag) {
          this.status = 1
          return this.status
        }
        if (!_this.isStart) {
          _this.bridge.closeVedio();
          this.store.commit('setLive', {
            defaultImg: null,
            status: '直播中',
          });
          _this.setMw();
          _this.isStart = true;
          _this.isAfter = false;
          _this.isBefore = false;
        }
        /* 直播后 ,当前时间在结束时间之后*/
      } else if (nowTimeTemp > endTimeTemp && nowTimeTemp <= tempAfterTime) {
        console.log('直播后');
        if (!_this.execFlag) {
          this.status = 2
          return this.status
        }
        if (!_this.isAfter) {
          _this.bridge.closeVedio();
          this.store.commit('setLive', {
            defaultImg: null,
            status: '直播后',
          });
          _this.setOldMw();
          _this.isAfter = true;
          _this.isStart = false;
          _this.isBefore = false;
        }
      } else {
        console.log('其他时间');
        if (!_this.execFlag) {
          this.status = 3
          return this.status
        }
        if (!_this.isBefore) {
          _this.bridge.closeVedio();
          this.store.commit('setLive', {
            defaultImg: null,
            status: '其他时间',
          });
          // _this.setBfMw();
          _this.isBefore = true;
          _this.isStart = false;
          _this.isAfter = false;
        }
      }
    };
    this.start = function (parame) {
      // _this.nowTime = parame.nowTime;
      _this.beforeTime = parame.beforeTime;
      _this.startTime = parame.startTime;
      _this.endTime = parame.endTime;
      _this.afterTime = parame.afterTime;
      _this.playUrl = parame.playUrl;
      _this.beforeImg = parame.beforeImg;
      _this.errorFlag = parame.errorFlag;
      _this.delayTime = parame.delayTime;
      _this.execFlag = !(!parame.execFlag)  ;    // 处理多个直播时使用.
      _this.bridge = parame.bridge;
      _this.store = parame.store;
      _this.vedioInfo = parame.vedioInfo;
      _this.store.commit('setVideoInfo', _this.vedioInfo);

      _this.getStatus();

      if (!_this.intTime) {
        _this.intTime = setInterval(function () {
          // console.log(new Date())
          _this.getStatus();
        }, 10000);
      }
    };
    this.startExecFlag = function () {
      _this.execFlag = true;
      _this.getStatus()
    }
    this.closeExecFlag = function () {
      _this.isStart = false;
      _this.isAfter = false;
      _this.isBefore = false;
      _this.execFlag = false
    }
    this.destroyTime = function () {
      if (_this.intTime) {
        clearInterval(_this.intTime);
      }
    };
  },
};
/*_frameWork 结束*/

//hs.onBlur  和  hs.onFocus , doSelect需要自己重写
function fObject(
  group,
  objindex,
  objid,
  up,
  down,
  left,
  right,
  touchCallback
) {
  this.group = group;
  this.objindex = objindex;
  this.objid = objid || group + '-' + objindex;
  this.up = up;
  this.down = down;
  this.left = left;
  this.right = right;
  this.touchCallback = touchCallback;

  this.doBlur = function () {
    if (typeof _frameWork.onBlur == 'function') {
      _frameWork.onBlur(this.group, this.objid, this.objindex);
    } else {
      console.log(
        'Error:you should implement the funcion hs.onBlur(groupid,objid,index)'
      );
    }
  };
  this.doFocus = function () {
    if (typeof _frameWork.onFocus == 'function') {
      _frameWork.onFocus(this.group, this.objid, this.objindex);
    } else {
      console.log(
        'Error:you should implement the funcion hs.onFocus(groupid,objid,index)'
      );
    }
  };
  this.doUp = function () {
    if (typeof this.up == 'function') {
      this.up(this);
    }
  };
  this.doDown = function () {
    if (typeof this.down == 'function') {
      this.down(this);
    }
  };
  this.doLeft = function () {
    if (typeof this.left == 'function') {
      this.left(this);
    }
  };
  this.doRight = function () {
    if (typeof this.right == 'function') {
      this.right(this);
    }
  };
  this.doSelect = function () {
    this.onSelect(this.group, this.objindex, this.objid);
  };
  fObjList.push(this);
}

function grabEvent(event) {
  var key_code = event.keyCode || event.which;
  var ret = 1;
  ret = _frameWork.defaultFun(key_code);
  return ret;
}

_frameWork.execute = function (key_code) {
  _frameWork.defaultFun(key_code);
};

/*
接口说明：
功能：DOM对象选择器
参数：selector，DOM对象的ID
返回：如果为找到指定对象，则返回null，否则返回找到的对象
*/
window.$ = function (selector) {
  if (typeof selector == 'string') {
    var t = document.getElementById(selector);
    if (typeof t === 'undefined') {
      return null;
    } else {
      return t;
    }
  } else {
    console.log('getElementById(' + selector + ') is null!');

    return null;
  }
};

/*兼容旧版ajax*/
_frameWork.ajax = new function () {
  var ajax = new _frameWork.AjaxObject();
  ajax.async = false;
  this.get = ajax.get;
  this.post = ajax.post;
}();

//将fObject 设置为  winodw的顶层对象属性
window.fObject = fObject;

window.document.onkeydown = grabEvent;
window.document.onirkeypress = grabEvent;
window.document.onsystemevent = grabEvent;

/*初始化默认事件*/
_frameWork.defaultEvenFn();

//----------hs 扩展函数---------------
_frameWork.isArray = function (obj) {
  return (
    Object.prototype.toString.call(obj) === '[object Array]' ||
    obj instanceof Array
  );
};
_frameWork.isObject = function (obj) {
  return typeof obj == 'object';
};

_frameWork.isFunction = function (obj) {
  return typeof obj == 'function';
};

_frameWork.isString = function (obj) {
  return typeof obj == 'string';
};

_frameWork.isBoolean = function (obj) {
  return typeof obj == 'boolean';
};

_frameWork.isNumber = function (obj) {
  return typeof obj == 'number';
};

_frameWork.isUndefined = function (obj) {
  return typeof obj == 'undefined';
};

/**
 * foreach方法
 * @param  items
 * @param  fn(value, index);
 */
_frameWork.forEach = (function () {
  if (![].forEach) {
    return function (items, fn, separator) {
      if (_frameWork.isString(items)) {
        separator = separator || '|';
        items = items.split(separator);
      }
      for (var i = 0, len = items.length; i < len; i++) {
        fn(items[i], i);
      }
    };
  } else {
    return function (items, fn) {
      [].forEach.call(items, fn);
    };
  }
})();

/**
 * 判断对象是否为空
 * @param obj
 */
_frameWork.isEmptyObject = function (obj) {
  for (var key in obj) {
    return false;
  }
  return true;
};

/**
 * 删除字符串首尾空白符
 * @param value
 * @returns {*}
 */
_frameWork.trim = function (value) {
  if (this.isString(value)) {
    var reg = /^\s+|\s+$/g;
    return value.replace(reg, '');
  }
  return value;
};

//设置css style
_frameWork.css = function (elem, value) {
  if (this.isString(value)) {
    cssText(elem, value);
  } else if (this.isObject(value)) {
    for (var m in value)
      elem.style[m] = value[m];
    return true;
  }
};

// 判断数组是否包含值
_frameWork.arrayIsContains = function (_arr, _v) {
  var flag = false;
  this.forEach(_arr, function (_item, _index) {
    if (_item === _v) {
      flag = true;
      return;
    }
  });
  return flag;
};


_frameWork.setBackObj = function (_objname, _backObj) {
  this.cookie.set(_objname, JSON.stringify(_backObj));
};


//视频自动播放
// chrome://flags/#autoplay-policy        设置成 no user gesture is required 就好了。

/*
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-action:none;
    touch-action:none;
    cursor: default;
*/

export default _frameWork;
